package cn.itcast.hotel.mq;

import cn.itcast.hotel.constans.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.annotation.Backoff;

/**
 * 通过mq的异步通知去处理es的数据更新
 */
@Configuration
public class MqHotelListener {
    @Autowired
    private IHotelService iHotelService;

    /**
     * 修改、新增数据-insert hotel
     */
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = MqConstants.HOTEL_INSERT_QUEUE,),
//            exchange = @Exchange(),
//            key = {""}
//    ))
    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void listenHotelInsertOrUpdate(Long id) {
        iHotelService.insertById(id);
    }

    /**
     * 删除数据-delete hotel
     */
    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void listenHotelDelete(Long id) {
        iHotelService.deleteById(id);
    }
}
